package com.bookmngsys.View;


import com.bookmngsys.entity.Book;
import com.bookmngsys.entity.BookInfo;
import com.bookmngsys.entity.Category;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.BeanUtils;

import java.util.Date;
import java.util.List;

/**
 * @author han
 */
@Getter
@Setter
public class BookInfoDto {
    private int bookId;
    private String isbn;
    private int categoryId;
    private String categoryName;
    private String bookName;
    private String author;
    private String publisher;
    private Date publishDate;
    private float unitPrice;
    private String img;
    private String summary;
    private int allNum;
    private String tags;
    private int lastNum;
    private int status = 1;
    private String rackNumber;
    private int reserveNum;
    private int lost;
    private int damage;


    public BookInfoDto convertToBookDto(BookInfo bookinfo, List<Book> books) {
        BookInfoDto bookInfoDto = new BookInfoDto();
        bookInfoDto.setBookId(bookinfo.getBookId());
        String isbn = bookinfo.getIsbn();
        for(Book book:books){
            if(book.getIsbn().equals(isbn)){
                bookInfoDto.setAllNum(book.getAllNum());
                bookInfoDto.setAuthor(book.getAuthor());
                bookInfoDto.setBookName(book.getBookName());
                bookInfoDto.setCategoryName(book.getCategory().getCategoryName());
                bookInfoDto.setImg(book.getImgUrl());
                bookInfoDto.setIsbn(book.getIsbn());
                bookInfoDto.setLastNum(book.getLastNum());
                bookInfoDto.setPublishDate(book.getPublishDate());
                bookInfoDto.setRackNumber(book.getRackNumber());
                bookInfoDto.setUnitPrice(book.getUnitPrice());
                bookInfoDto.setLost(bookinfo.getLost());
                bookInfoDto.setDamage(bookinfo.getDamage());
            }
        }
        return bookInfoDto;
    }

}
